<template>
	<view class="">
		<home ref="Home" v-show="PageUrl === 'home'"></home>
		<home2 ref="Home2" v-show="PageUrl === 'home2'"></home2>
		<user ref="User" v-show="PageUrl === 'user'"></user>
		<view class="tabber-wrapper">
			<view class="tabber-item" :class="{ show: item.url === PageUrl }" v-for="(item, index) in TabBarList" :key="index"
			 @click="tabbarClick(item)">
				<image :src="item.url === PageUrl ? item.check_image : item.image" mode="scaleToFill"></image>
				<text>{{ item.name }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import Home from '@/pages/home/home.vue';
	import Home2 from '@/pages/home2/home2.vue';
	import User from '@/pages/user/user.vue';
	export default {
		components: {
			Home,
			Home2,
			User
		},
		data() {
			return {
				PageUrl: 'home',
				TabBarList: [{
						name: '首页',
						url: 'home',
						image: '/static/index/index_light.png',
						check_image: '/static/index/index_hide.png'
					},
					{
						name: '体验营',
						url: 'home2',
						image: '/static/index/index2_light.png',
						check_image: '/static/index/index2_hide.png'
					},
					{
						name: '我的',
						url: 'user',
						image: '/static/index/user_light.png',
						check_image: '/static/index/user_hide.png'
					}
				]
			};
		},
		onLoad(o) {
			console.log(o);
			if (o.token) {
				this.$db._SetStorage('token', o.token);
				var ua = navigator.userAgent.toLowerCase();
				console.log(ua.match(/android/i));
				if (ua.match(/android|iPhone|iPad/i)) {
					window.history.go(-1);
				} else {
					window.history.go(-2);
				}
			}
			if(o.url){ 
				this.PageUrl = o.url
			}
		},
		mounted() {
			// this.$refs.Home.getData();
			// this.$refs.User.getData();
		},
		onPullDownRefresh() {
			switch (this.PageUrl) {
				case 'home':
					this.$refs.Home.getData();
					break;
				case 'home2':
					this.$refs.Home2.getData();
					break;
				case 'user':
					this.$refs.User.getData();
					break;
				default:
					break;
			}
			// 关闭刷新
			uni.stopPullDownRefresh();
		},
		methods: {
			tabbarClick: function(item) {
				this.PageUrl = item.url;
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background: #f9f9f9;
		padding-bottom: 90rpx;
	}

	.tabber-wrapper {
		position: fixed;
		left: 0;
		bottom: 0;
		height: 90rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #ffffff;

		.tabber-item {
			flex: 0 0 264rpx;
			display: flex;
			flex-flow: column;
			justify-content: center;
			align-items: center;

			image {
				width: 48rpx;
				height: 48rpx;
			}

			text {
				font-size: 22rpx;
				color: #000000;
			}

			&.show {
				text {
					color: rgba(176, 162, 119, 1);
				}
			}
		}
	}
</style>
